/*
 * Copyright © 2004-2014 chenYuan. All rights reserved.
 * @Website:wwww.jspx.net
 * @Mail:39793751@qq.com
 * @author: chenYuan , 陈原
 * @License: Jspx.net Framework Code is open source (LGPL)，Jspx.net Framework 使用LGPL 开源授权协议发布。
 * @jvm:jdk1.6+  x86/amd64
 *
 */
package com.jspx.sober.config;

import javax.sql.DataSource;
import javax.sql.XADataSource;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

/**
 * Created by IntelliJ IDEA.
 * User: chenYuan
 * Date: 2008-8-7
 * Time: 10:43:22
 */
public class XADataSourceProxy implements DataSource, Serializable {
    //    final static private com.jspx.boot.Logger log = LoggerFactory.getLogger(XADataSourceProxy.class.getName());
    private XADataSource dataSource;

    public XADataSourceProxy(XADataSource dataSource) {
        this.dataSource = dataSource;
    }

    public Connection getConnection() throws SQLException {
        return dataSource.getXAConnection().getConnection();
    }

    public Connection getConnection(String username, String password) throws SQLException {
        return dataSource.getXAConnection().getConnection();
    }

    public java.io.PrintWriter getLogWriter() throws SQLException {
        return dataSource.getLogWriter();
    }

    public void setLogWriter(java.io.PrintWriter out) throws SQLException {
        dataSource.setLogWriter(out);
    }

    public void setLoginTimeout(int seconds) throws SQLException {
        dataSource.setLoginTimeout(seconds);
    }

    public int getLoginTimeout() throws SQLException {
        return dataSource.getLoginTimeout();
    }

    /**
     * Return the parent Logger of all the Loggers used by this data source. This
     * should be the Logger farthest from the root Logger that is
     * still an ancestor of all of the Loggers used by this data source. Configuring
     * this Logger will affect all of the log messages generated by the data source.
     * In the worst case, this may be the root Logger.
     *
     * @return the parent Logger for this data source
     * @throws java.sql.SQLFeatureNotSupportedException
     *          if the data source does not use <code>java.util.logging<code>.
     * @since 1.7
     */

    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        return Logger.getLogger(XADataSourceProxy.class.getName());
    }

    public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException {
        return null;
    }

    public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException {
        return false;
    }
}